﻿@{    
    Page.Title = "OrderSimple";

    if (!IsPost) {
        Response.Redirect("~/Products");
    }

    var db = Database.Open("bakery");
    var productId = Request["ProductId"];
    var product = db.QuerySingle("SELECT * FROM PRODUCTS WHERE ID = @0", productId);
}

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script> 
<script type="text/javascript">
    $(document).ready(function() {
        var price = parseFloat($("#orderPrice").html()).toFixed(2);
        $("#orderTotal").html(price);
        $("#orderQty").blur(function() {
            var quantity = parseInt($("#orderQty").val());
            $("#orderTotal").html((price * quantity).toFixed(2));
        });
    });
</script>

<h2>Order Now</h2>
<form id="myform" action="OrderSimpleSuccess" method="post">
    <fieldset>
        <div class="order">
            <h3>@product.Name</h3>
            <img src="@Href("~/Images/"+ product.ImageName)" alt="@product.Name"/>
        </div>
        <input type="hidden" name="productId" value="@product.Id"/><br/>
    
        <label for="orderQty">Quantity:</label>
        <input type="text" id="orderQty" name="orderQty" value="1"/><br/>

        <label for="orderEmail">Your PayPal Id:</label>
        <input type="text" id="orderEmail" name="orderEmail"/> e.g. james_1284183860_per@yahoo.com <br/>
    
        <label for="orderShipping">Shipping Address:</label>
        <textarea rows="5" cols="20" name="orderShipping"></textarea><br/>
    </fieldset>
    
    <div class="summary group">
        <label for="orderPrice">Price: $</label>
        <span id="orderPrice" name="orderPrice">@string.Format("{0:f}", product.Price)</span>
        <label for="orderTotal">Estimated Total: $</label>
        <span id="orderTotal" name="orderTotal"></span>
    </div>
    
    <input type="submit" value="Simple Pay Order"/>
</form>